約 6,026,506 件
https://w.atwiki.jp/s603rd/pages/113.html
Landmarks Google maps マレーシアに旅行に行った際に、Langkawiと言う島に滞在した。 その時に幾つかのオプショナルツアーに行ったのだが、諸島を巡るツアーだと 自分が何処にいるのか分からない。地図持参でガイドに聞きながらでは ツアーの邪魔になる。 そんな訳で、今回は有り合わせのLandmarkで位置情報を取得しつつ ツアーに臨んでみた。 Landmarkでの位置情報取得は至って簡単で、New landmarkから Current positionを選択するだけだ。GPSで位置情報を取得して、 Landmarkの登録画面が開く。 名前は後で変えられるので、取り敢えず何となく分かるような名前にする。 そんな事を繰り返し旅行から帰ってきてGoogleMaps(Web)を開き、 ファイルからの位置情報取得に挑んだ。 マイマップで編集モードにするとインポートが表示される。 インポートを押すとファイルの選択画面が表示される。 ここにLandmarkで取得した位置情報をロードさせてみる。 一瞬うまくロードされたように見えるが、実際には位置が表示されない。 KMLでは無いので仕方がない。XML形式なので手で編集もできるのだが、 それも面倒なので、Landmarkの位置情報をGoogleMapsに入力してみる。 LandmarkのLatitudeとLongitudeの数値部分をカンマ区切りで入力する。 入力したら「地図を検索」を押してみる。 そうすると位置が表示された。右上のAがそれだ。 位置情報が多いと嫌になりそうだが、今回はそれほど多くなかったので 取得した位置情報でマイマップを作成してみた。 右下の小さい島はシュノーケリングツアーで行った場所なのだが、 正直こんな所にある島だとは知らなかった。 街中なら後で地図で確認できるが、島のボートツアー等では通ったルートも分かりにくい。 そんな時には思いのほか役に立ちそうだ。 尚、位置情報での検索はS60版のGoogleMapsでも使う事が出来るが、S60のGoogleMapsから 直接Landmarksが呼び出せるので意味は無い。 これで衛星通信でも出来れば、遭難しても位置情報が送れたり出来るのだが。 因みに有償のGPS Utilitiesを使えばKML形式で位置情報をトレースしてくれるので、 後でルート確認にも使える。
https://w.atwiki.jp/tonipura/pages/18.html
目次 Google Data APIリンク集公式 リファレンス 入門記事 まとめ記事 Google Data API リンク集 公式 Google CodeGoogle Data API - Google Code リファレンス 入門記事 [ThinkIT] オープンなAPIをさわってみる (1/3) http //www.thinkit.co.jp/free/article/0606/17/index.html まとめ記事 【Google Developer Day 2008】いつの間にか、大量のサービスをサポート「Google Data API」のまとめ:CodeZine Google CalendarGoogle Calendar APIリンク集公式 リファレンス 入門記事 まとめ記事
https://w.atwiki.jp/almighty/pages/16.html
https://w.atwiki.jp/api_programming/pages/181.html
下位ページ Calendar Drive Gmail Logger SpreadSheet Content 基本文法やメソッドはjavascriptに準ずる Eclipseから編集する webアプリケーションとして CORS スクリプト中で別のスクリプトを呼びたしたいリンクさせて使えるか? メッセージボックス 外部APIを叩く(Httpリクエストを送る) 外部からAPIで操作する 別プロジェクトの、自作ライブラリを使用する 基本文法やメソッドはjavascriptに準ずる Javascript Eclipseから編集する プラグインがある。機能上に制約があるので、通常はScript Editerで良さそう。たまにインデントが乱れたりするので、そのような場合はEclipseに持ち帰って、コードチェックを掛けるとか? 同じファイルを、①Script Editorで編集→②保存、③Eclipseで編集→④保存としたら、ちゃんと④で警告が出た。 ただし、 プロジェクトの新規作成は非対応(プロジェクトのインポートのみ) プロジェクト名の変更もできなさそう。 gsファイル、htmlファイルはルートフォルダに。その他のタイプのファイルや、サブフォルダのファイルはgoogleドライブではApps Scriptの一部にみなされない。 自動補完機能はライブラリに対しては提供されていない?(Autocomplete suggestions are not provided for libraries or advanced Google services.) ごくごく最近追加されたメソッドにも対応していないかも。スクリプトエディタで有効なら、ま、まだちゃんと走るけど。 Eclipse 使い方:先に作っておく? ファイル→インポート→google→GAS 新しいファイルの追加 File New File拡張子は.gsか.html 編集内容のアップロード 自動的にされている Eclipseでの保存時に、プロジェクトのファイルビューのアイコンに×マークがでる(アップロード未完)。バツが消えたらアップロード完。 webアプリケーションとして htmlファイルを設定 https //developers.google.com/apps-script/guides/html/ ようするに、getリスエストが来た時の関数 doGet内に、表示させるhtmlを指定しておけばよい。 return HtmlService.createHtmlOutputFromFile( index ); CORS https //developer.mozilla.org/ja/docs/HTTP_access_control あるドメインから取得したページ内で、別のドメインのページを呼び出せない。 imgタグ内、scriptタグ内など、例外はある(ので、CORSを知らないとなんでできないの?と思ってしまう) 実際には、上記のような例外をのぞいて、ドメインが違うサーバへのリクエスト(レスポンス)は受け付けない。 ここを読む限り、GASサーバへのXMLHttpRequestは不可。 GAS内で表示された、htmlから(クライアントから)実行するための機能はある(google.script.run)が、あんまり解決になってない。やりたいことが、よそのサーバから自分のscript(Spreadsheet)とも連携、なので。 スクリプト中で別のスクリプトを呼びたしたい まだ実施していないが、スクリプトファイルを公開状態にすれば使えるようになるみたい。 使われるスクリプトを開いて「ファイル」→「プロジェクトのプロパティ」 プロジェクトキーを控える 使うスクリプトで「リソース」→「ライブラリ」 ライブラリのキーを入力する http //itami.info/tech/14-memorandum/188-googleappsscriptincludfunctions.html Google Apps Scriptで作った関数類をライブラリ化しよう リンクさせて使えるか? 無理っぽい。HTMLならできるけど。 無理やりやるなら、こんな方法。 GASのライブラリを使って楽したい② 外部のJSライブラリを使ってみる( 3」[_] http //qiita.com/soundTricker/items/5a7e050a2a20f3e3938a メッセージボックス Browser.msgbox(str) msgBox(prompt) 外部APIを叩く(Httpリクエストを送る) Class UrlFetchApp GASで外部APIと連携 - Qiita External APIs 外部からAPIで操作する Google App Scriptではなく、Java(とかの)プログラムから操作したい とりあえずJavaでプログラムを組むか。 https //developers.google.com/api-client-library/java/ ライブラリを取得する APIの使用許可を得る(認証) http //a-auto50.blogspot.jp/2015/06/drive-rest-apijavagoogle-drive.html 別プロジェクトの、自作ライブラリを使用する 大まかな流れ 自作ライブラリ側スクリプトIDをメモる 使用するプロジェクト側リソース - ライブラリ で スクリプトID を指定して読み込む http //redsnapper.hatenablog.com/entry/2017/05/30/153241 ライブラリを使い側 https //developers.google.com/apps-script/guides/libraries?hl=ja
https://w.atwiki.jp/api_programming/pages/41.html
下位ページ トリガ Content 基本文法やメソッドはjavascriptに準ずる Eclipseから編集する webアプリケーションとして CORS スクリプト中で別のスクリプトを呼びたしたいリンクさせて使えるか? メッセージボックス 外部APIを叩く 外部からAPIで操作する Google Apps Script 内に作った関数を別のPJTから使用する 基本文法やメソッドはjavascriptに準ずる Javascript Eclipseから編集する プラグインがある。機能上に制約があるので、通常はScript Editerで良さそう。たまにインデントが乱れたりするので、そのような場合はEclipseに持ち帰って、コードチェックを掛けるとか? 同じファイルを、①Script Editorで編集→②保存、③Eclipseで編集→④保存としたら、ちゃんと④で警告が出た。 ただし、 プロジェクトの新規作成は非対応(プロジェクトのインポートのみ) プロジェクト名の変更もできなさそう。 gsファイル、htmlファイルはルートフォルダに。その他のタイプのファイルや、サブフォルダのファイルはgoogleドライブではApps Scriptの一部にみなされない。 自動補完機能はライブラリに対しては提供されていない?(Autocomplete suggestions are not provided for libraries or advanced Google services.) ごくごく最近追加されたメソッドにも対応していないかも。スクリプトエディタで有効なら、ま、まだちゃんと走るけど。 Eclipse 使い方:先に作っておく? ファイル→インポート→google→GAS 新しいファイルの追加 File New File拡張子は.gsか.html 編集内容のアップロード 自動的にされている Eclipseでの保存時に、プロジェクトのファイルビューのアイコンに×マークがでる(アップロード未完)。バツが消えたらアップロード完。 webアプリケーションとして htmlファイルを設定 https //developers.google.com/apps-script/guides/html/ ようするに、getリスエストが来た時の関数 doGet内に、表示させるhtmlを指定しておけばよい。 return HtmlService.createHtmlOutputFromFile( index ); CORS https //developer.mozilla.org/ja/docs/HTTP_access_control あるドメインから取得したページ内で、別のドメインのページを呼び出せない。 imgタグ内、scriptタグ内など、例外はある(ので、CORSを知らないとなんでできないの?と思ってしまう) 実際には、上記のような例外をのぞいて、ドメインが違うサーバへのリクエスト(レスポンス)は受け付けない。 ここを読む限り、GASサーバへのXMLHttpRequestは不可。 GAS内で表示された、htmlから(クライアントから)実行するための機能はある(google.script.run)が、あんまり解決になってない。やりたいことが、よそのサーバから自分のscript(Spreadsheet)とも連携、なので。 スクリプト中で別のスクリプトを呼びたしたい まだ実施していないが、スクリプトファイルを公開状態にすれば使えるようになるみたい。 使われるスクリプトを開いて「ファイル」→「プロジェクトのプロパティ」 プロジェクトキーを控える 使うスクリプトで「リソース」→「ライブラリ」 ライブラリのキーを入力する http //itami.info/tech/14-memorandum/188-googleappsscriptincludfunctions.html Google Apps Scriptで作った関数類をライブラリ化しよう リンクさせて使えるか? 無理っぽい。HTMLならできるけど。 無理やりやるなら、こんな方法。 GASのライブラリを使って楽したい② 外部のJSライブラリを使ってみる( 3」[_] http //qiita.com/soundTricker/items/5a7e050a2a20f3e3938a メッセージボックス Browser.msgbox(str) msgBox(prompt) 外部APIを叩く Class UrlFetchApp GASで外部APIと連携 - Qiita External APIs 外部からAPIで操作する Google App Scriptではなく、Java(とかの)プログラムから操作したい とりあえずJavaでプログラムを組むか。 https //developers.google.com/api-client-library/java/ ライブラリを取得する APIの使用許可を得る(認証) http //a-auto50.blogspot.jp/2015/06/drive-rest-apijavagoogle-drive.html Google Apps Script 内に作った関数を別のPJTから使用する https //www.lisz-works.com/entry/gas-create-lib
https://w.atwiki.jp/webdesignmemo/pages/39.html
Google Mapsをウェブサイトに設置するのはとても簡単です。 生成されたHTMLコードを埋め込むだけだし・・・ しかし、これをFlashに埋め込むとなるとけっこう手間です flexSDKという開発ツールを使ったり、コマンドプロンプトを使ったりいろいろメンドーだ・・・ そこでgoogleで紹介されている方法のひとつ Flash CS3 のAS3を使った方法でやってみたいと思います ただ、チュートリアル的なサイトがどこにもなく、googleのチュートリアル(英語?)だけが頼り。 さて、どうなるものか・・・ http //code.google.com/apis/maps/documentation/flash/tutorial-flash.html を参考に。 まず、http //maps.googleapis.com/maps/flash/release/sdk.zip からコンポーネントをダウンロードします。→解凍 C \Program Files\Adobe\ Adobe Flash CS3\language\Configuration\Componentsのとこに"Google"フォルダをつくりその中に先ほど解凍したコンポーネントを入れろとあります。 (注意)コンポーネントのファイルは解凍したsdkフォルダのlibの中、map【なんとかかんとか】swcとなっているやつ。(map_flex、、、というやつはflexバージョンなので今回は使わない。) (注意)languageのとこはFlashの言語がはいります。日本語バージョンなら C \Program Files\Adobe\ Adobe Flash CS3\ja\Configuration\Component・・・となる Flashで新規ドキュメントを作成 AS3で作成します ウィンドウ→コンポーネントで Googleの中にGoogleMapsLibraryがあるのを確認 ライブラリパネルを開き、GoogleMapsLibraryをライブラリにドラッグ&ドロップしておきます ウィンドウ→アクションでアクションスクリプトパネルを開き タイムラインの1フレームめを選択し、パネルに下記アクションスクリプトを書く import com.google.maps.LatLng; import com.google.maps.Map; import com.google.maps.MapEvent; import com.google.maps.MapType; var map Map = new Map(); map.key = "your_api_key"; map.setSize(new Point(stage.stageWidth, stage.stageHeight)); map.addEventListener(MapEvent.MAP_READY, onMapReady); this.addChild(map); function onMapReady(event Event) void { map.setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE); } "your_api_key"→APIのkeyを取得してここに記入する ローカルで使いたい時のサンプルコード【ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g】 (注意)googleのチュートリアルのサンプルコードは少し間違っていますのでコピペ使用の際は注意! stageHeightの後ろの")"が足りない。 とりあえずムービープレビュー→動きます あとはAPIkeyを取得してweb上で動かしてみる
https://w.atwiki.jp/api_programming/pages/37.html
下位ページ Content 認証リクエスト OAuth2.0 の概要 WebサーバアプリケーションのOauth 2.0認証 Using OAuth 2.0 for Web Server Applications 概要 認証プロトコルについて OAuth 2.0 による認証 いろんな言語のライブラリ web application credentialsを作る web application credentials を得るステップ Preparing to start the OAuth 2.0 flowGoogle's OAuth 2.0 サーバにリダイレクト OAuth 2.0 serverのレスポンスを扱う Google APIsを呼び出す サンプル完全版Incremental authorization Offline accessトークンのリクエストjava? リダイレクトのURLから、codeを処理する authorization code と access token の交換 認証リクエスト Google APIにリクエストを送るには、アプリケーションの「identify」が必要で、その方法は2つある。 OAuth 2.0 token (which also authorizes the request) API key どちらをつかうのか、は以下で決まる。 プライベートデータを使うときは、OAuth 2.0 token でなければならない。アプリケーションには API key も配布されるが必須でない。 パブリックデータを使うときは the API key でも OAuth 2.0 token 使いやすい方で良い, or both—whatever option is most convenient for you. OAuth2.0 の概要 https //developers.google.com/identity/protocols/OAuth2?csw=1 WebサーバアプリケーションのOauth 2.0認証 Using OAuth 2.0 for Web Server Applications Google API の認証 Google Identity Platform https //developers.google.com/identity/protocols/OAuth2WebServer Using OAuth 2.0 for Web Server Applications Google APIsを使うために、Google API Client Libraries or Google OAuth 2.0 endpoints が使える。 OAuth 2.0 で、ユーザは、ユーザ名やパスワードをプログラムに渡すことなく、Google アプリケーションのデータが使える。 概要 まず、APIコンソールでプロジェクトの「web application credentials」をつくる。アプリケーションがユーザーデータにアクセスする必要がある場合は、ユーザーはGoogle s OAuth 2.0 serverにリダイレクトされる。OAuth 2.0 server はユーザ承認をして、アプリケーションからのデータアクセスに必要な「consent」を得る。 OAuth 2.0 serverはユーザーをアプリケーションにリダイレクトする(戻す)。このとき、承認コードを返す。アプリケーションで承認コードをアクセストークンに交換する。 アプリケーションは承認コードを使って、Google API にアクセスする。 When you use a Google API Client Library to handle your application s OAuth 2.0 flow, the client library keeps track of when a stored access token can be used and when the application must re-acquire consent, generates correct redirect URLs, and helps to implement redirect handlers that exchange authorization codes for access tokens. An application that carries out the OAuth 2.0 flow without using a client library must correctly complete the same steps. Client libraries The language-specific examples on this page make use of the Google API Client Libraries, which make API authorization with OAuth 2.0 simpler. To run the example code, you must first install the client library for your language. 認証プロトコルについて OAuth 2.0しかないが、Google Sign-In が使えるアプリケーションなら、違う「扱い方」をすることが可能 OAuth 2.0 による認証 Requests to the Google Sheets API for non-public user data must be authorized by an authenticated user. The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you re writing. The following general process applies to all application types アプリケーションを作成したら、Google API Console に使用登録をする。これに関する細かな情報は後述。 (Sheets API を使うのであれば)Google Sheets API を Google API Console でアクティベートする。(使用する API がリストになければ、このステップは飛ばす) アプリケーションがユーザーデータを必要とするのであれば、Google に アクセススコープを要求する。 Google はユーザーに確認画面を表示し、アプリケーションを認証するか尋ねる。 ユーザが認証したら、Google がアプリケーションにアクセストークンを発行する。 アプリケーションがユーザーデータ(プライベートデータ)を要求する場合は、アクセストークンをつけて要求する。 Google はリクエストとトークンが有効と判断したら、要求されたデータを返す 以上が基本の流れで、ところどころ追加ステップが必要になる。例えば、トークンの有効期限が切れた場合のリフレッシュ作業など。 いろんな言語のライブラリ 省略 web application credentialsを作る All web applications that use OAuth 2.0 must have credentials that identify the application to the OAuth 2.0 server. Applications that have these credentials can access the APIs that you enabled for your project. web application credentials を得るステップ APIコンソールの認証情報ページへ。 (まだ作っていなければ)「認証情報を作成」をクリックして、OAuth クライアント ID を選択する。 次に、クライアントIDとクライアントSecretを探す。 リダイレクトURIも編集。リダイレクトURIはエンドポイントで、レスポンスに乗ってくる情報を処理する。ローカルマシンで試す場合は、http //localhost 8080みたいなのも可。 client_secrets.jsonファイルをダウンロードしてセキュリティ性を保って保管する(ほうがいい) Important Do not store the client_secrets.json file in a publicly-accessible location, and if you share the source code to your application—for example, on GitHub—store the client_secrets.json file outside of your source tree to avoid inadvertently sharing your client credentials. Preparing to start the OAuth 2.0 flow If you are using a Google API client library to handle the OAuth 2.0 flow, configure the client object, which you will use to make OAuth 2.0 requests. If you are handling the flow by directly accessing the OAuth 2.0 endpoints, just take note of the client ID that you created in the previous step and the scopes you need to request. To configure the client object HTTP/REST Take note of the following values Your app s client ID and client secret, which you created in Creating web application credentials. The scopes that your app needs to request. See the documentation for the APIs your app uses for the required scopes. Google s OAuth 2.0 サーバにリダイレクト HTTP/REST https //accounts.google.com/o/oauth2/v2/auth HTTP はだめ。HTTPSで。 https //accounts.google.com/o/oauth2/v2/auth? scope=email%20profile state=security_token%3D138r5719ru3e1%26url%3Dhttps //oa2cb.example.com/myHome redirect_uri=https%3A%2F%2Foauth2.example.com%2Fcode , response_type=code client_id=812741506391.apps.googleusercontent.com The set of query string parameters supported by the Google Authorization Server for web server applications are Parameter Values Description response_type code Determines whether the Google OAuth 2.0 endpoint returns an authorization code. Web server applications should use code. client_id クライアントID リクエストを出したクライアントの特定 required redirect_uri コンソールで登録したリダイレクトURIの一つ 登録されたURIとピッタリ合わないとだめ。(http / https も scope アプリケーションにリクエストするパーミッション(スペース区切り) 使うスコープは承認画面でユーザーに公開される。要求されたパーミッション数と、ユーザーの同意を得る可能性との間には逆の可能性があります。使えるスコープの種類は、APIs Explorerで確認のこと。It is generally a best practice to request scopes incrementally, at the time access is required, rather than up front. 例えば、For example, an app that wants to support purchases should not request Google Wallet access until the user presses the “buy” button; see Incremental authorization. state Any string Provides any state that might be useful to your application upon receipt of the response. The Google Authorization Server roundtrips this parameter, so your application receives the same value it sent. To mitigate against cross-site request forgery (CSRF), it is strongly recommended to include an anti-forgery token in the state, and confirm it in the response. See OpenID Connect for an example of how to do this. access_type online / offline Indicates whether your application needs to access a Google API when the user is not present at the browser. This parameter defaults to online. If your application needs to refresh access tokens when the user is not present at the browser, then use offline. This will result in your application obtaining a refresh token the first time your application exchanges an authorization code for a user. prompt Space-delimited, case-sensitive list of prompts to present the user. If you don t specify this parameter, the user will be prompted only the first time your app requests access. 可能なあたいとして、"none" 画面を出さないMust not be specified with other values. consentPrompt the user for consent select_accountPrompt the user to select an account login_hint email address or sub identifier When your application knows which user it is trying to authenticate, it can provide this parameter as a hint to the Authentication Server. Passing this hint will either pre-fill the email box on the sign-in form or select the proper multi-login session, thereby simplifying the login flow. include_granted_scopes true / false If this is provided with the value true, and the authorization request is granted, the authorization will include any previous authorizations granted to this user/application combination for other scopes; see Incremental Authorization. After you create the request URL, redirect the user to it. Google s OAuth 2.0 server will authenticate the user and obtain consent from the user for your application to access the requested scopes. The response will be sent back to your application using the redirect URL you specified. OAuth 2.0 serverのレスポンスを扱う ユーザがアクセス要求を承認すると、認証コードが送られてくる。 承認しなければ、レスポンスにはエラーメッセージが含まれてくる。 All responses are returned to the web server on the query string, as shown below エラー https //oauth2.example.com/auth?error=access_denied 承認 https //oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7 Important If your response endpoint renders an HTML page, any resources on that page will be able to see the authorization code in the URL. Scripts can read the URL directly, and all resources may be sent the URL in the Referer HTTP header. Carefully consider if you want to send authorization credentials to all resources on that page (especially third-party scripts such as social plugins and analytics). To avoid this issue, we recommend that the server first handle the request, then redirect to another URL that doesn t include the response parameters. 認証コードを受け取ったら、アクセストークンと交換 ここにアクセス https //www.googleapis.com/oauth2/v4/token 使用するパラメータ Field Description code The authorization code returned from the initial request. client_id The client ID obtained from the API Console. client_secret The client secret obtained from the API Console. redirect_uri One of the redirect URIs listed for this project in the API Console. grant_type As defined in the OAuth 2.0 specification, this field must contain a value of authorization_code. リクエスト例 POST /oauth2/v4/token HTTP/1.1 Host www.googleapis.com Content-Type application/x-www-form-urlencoded code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7 client_id=8819981768.apps.googleusercontent.com client_secret={client_secret} redirect_uri=https //oauth2.example.com/code grant_type=authorization_code リクエストが通ると以下のレスポンスが戻る Field Description access_token Google APIにアクセスするためのトークン refresh_token 新しいアクセストークンを得るためのトークン。ユーザが承認を取り消すまで有効。このフィールドは access_type=offline が認証コードリクエストに含まれていれば、only present expires_in The remaining lifetime of the access token. token_type Identifies the type of token returned. At this time, this field will always have the value Bearer. レスポンスはJSONで帰ってくる { "access_token" "1/fFAGRNJru1FTz70BzhT3Zg", "expires_in" 3920, "token_type" "Bearer" } Note Other fields may be included in the response, and your application should not treat this as an error. The set shown above is the minimum set. Google APIsを呼び出す HTTP/REST access tokenを使って、APIを呼び出す。access token は (サーバログに残ってしまうので良くないが)"access_token" としてパラメータに含めるか、 (推奨は)HTTPヘッダの Authorization Bearer に含める。 You can try out all the Google APIs and view their scopes at the OAuth 2.0 Playground. 例 A call to the drive.files endpoint (the Drive API) using the access_token query string parameter might look like the following, though you ll need to specify your own access token GET https //www.googleapis.com/drive/v2/files?access_token=1/fFBGRNJru1FQd44AzqT3Zg Authorization Bearer HTTP header を使って同じことをすると GET /drive/v2/files HTTP/1.1 Authorization Bearer 1/fFBGRNJru1FQd44AzqT3Zg Host googleapis.com You can try out with the curl command-line application. Here s an example using the HTTP header option (preferred) curl -H "Authorization Bearer 1/fFBGRNJru1FQd44AzqT3Zg" https //www.googleapis.com/drive/v2/files Or, alternatively, the query string parameter option curl https //www.googleapis.com/drive/v2/files?access_token=1/fFBGRNJru1FQd44AzqT3Zg Google/Sheets API サンプル完全版 The following example prints a JSON-formatted list of files in a user s Google Drive after the user authenticates and gives consent for the application to access the user s Drive files. HTTP/REST This example in Python uses the Flask framework and the Requests library to demonstrate the OAuth 2.0 web flow. Note that using the Python client library is easier and is the recommended way to implement this flow. import json import flask import requests app = flask.Flask(__name__) CLIENT_ID = 123456789.apps.googleusercontent.com CLIENT_SECRET = abc123 # Read from a file or environmental variable in a real app SCOPE = https //www.googleapis.com/auth/drive.metadata.readonly REDIRECT_URI = http //example.com/oauth2callback @app.route( / ) def index() if credentials not in flask.session return flask.redirect(flask.url_for( oauth2callback )) credentials = json.loads(flask.session[ credentials ]) if credentials[ expires_in ] = 0 return flask.redirect(flask.url_for( oauth2callback )) else headers = { Authorization Bearer {} .format(credentials[ access_token ])} req_uri = https //www.googleapis.com/drive/v2/files r = requests.get(req_uri, headers=headers) return r.text @app.route( /oauth2callback ) def oauth2callback() if code not in flask.request.args auth_uri = ( https //accounts.google.com/o/oauth2/v2/auth?response_type=code client_id={} redirect_uri={} scope={} ).format(CLIENT_ID, REDIRECT_URI, SCOPE) return flask.redirect(auth_uri) else auth_code = flask.request.args.get( code ) data = { code auth_code, client_id CLIENT_ID, client_secret CLIENT_SECRET, redirect_uri REDIRECT_URI, grant_type authorization_code } r = requests.post( https //www.googleapis.com/oauth2/v4/token , data=data) flask.session[ credentials ] = r.text return flask.redirect(flask.url_for( index )) if __name__ == __main__ import uuid app.secret_key = str(uuid.uuid4()) app.debug = False app.run() Incremental authorization In the OAuth 2.0 protocol, your app requests authorization to access resources which are identified by scopes, and assuming the user is authenticated and approves, your app receives short-lived access tokens which let it access those resources, and (optionally) refresh tokens to allow long-term access. It is considered a best user-experience practice to request authorization for resources at the time you need them. For example, an app that lets people sample music tracks and create mixes might need very few resources at sign-in time, perhaps nothing more than the name of the person signing in. However, saving a completed mix would require access to their Google Drive. Most people would find it natural if they only were asked for access to their Google Drive at the time the app actually needed it. In this case, at sign-in time the app might request the profile scope to perform basic sign-in, and then later request the https //www.googleapis.com/auth/drive.file scope at the time of the first request to save a mix. Using the procedures described in Using OpenID Connect and Using OAuth 2.0 to Access Google APIs would normally result in your app having to manage two different access tokens. To avoid this complexity, you can include previously granted scopes in your authorization requests. For example HTTP/REST GET https //accounts.google.com/o/oauth2/v2/auth? scope=https //www.googleapis.com/auth/drive.file state=security_token%3D138r5719ru3e1%26url%3Dhttps //oa2cb.example.com/myHome redirect_uri=https%3A%2F%2Fmyapp.example.com%2Fcallback response_type=code client_id=8127352506391.apps.googleusercontent.com prompt=consent include_granted_scopes=true Let s call the resulting authorization the "combined authorization"; the following apply You can use the access tokens you get to access the resources corresponding to any of the scopes that are rolled into the combined authorization. When you use the refresh token for a combined authorization, the new access tokens represent the combined authorization and can be used for any of its scopes. The combined authorization includes any previously granted authorizations even if they were requested from different clients. For example, if you requested the profile scope from a desktop app, and then issued the request in the example URI above for the same user from a mobile app, and it was granted, the combined authorization would include both scopes. When you revoke a token which represents a combined authorization, all of the authorizations are revoked simultaneously; this means that if you retain a token for one of the previous authorizations, it will stop working. When you make an authorization request with granted scopes included, the Google authorization server rolls the authorization request together with all the previous authorizations granted to the requesting user from the requesting app. Offline access ユーザが使っていない場合でもAPIにアクセスする必要がある場合があるかも。たとえば、バックアップの場合や「月曜8時にBlobをポスト」のような場合。 このタイプのアクセスを「offline」と呼び、ウェブサーバアプリはオフラインリクエストができる。 これに対し、通常のアクセスはonlineである。 HTTP/REST If your application needs offline access to a Google API, then the request for an authorization code should include the access_type parameter, where the value of that parameter is offline. For example https //accounts.google.com/o/oauth2/v2/auth? scope=email%20profile state=security_token%3D138r5719ru3e1%26url%3Dhttps //oa2cb.example.com/myHome redirect_uri=https%3A%2F%2Foauth2.example.com%2Fcode response_type=code client_id=812741506391.apps.googleusercontent.com access_type=offline The first time a given user s browser is sent to this URL, they see a consent page. If they grant access, then the response includes an authorization code which may be redeemed for an access token and a refresh token. An example of an authorization code exchange is shown below POST /oauth2/v4/token HTTP/1.1 Host www.googleapis.com Content-Type application/x-www-form-urlencoded code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7 client_id=8819981768.apps.googleusercontent.com client_secret={client_secret} redirect_uri=https //oauth2.example.com/code grant_type=authorization_code If this is the first time the application has exchanged an authorization code for a user, then the response includes an access token and a refresh token, as shown below { "access_token" "1/fFAGRNJru1FTz70BzhT3Zg", "expires_in" 3920, "token_type" "Bearer", "refresh_token" "1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI" } Important When your application receives a refresh token, it is important to store that refresh token for future use. If your application loses the refresh token, it will have to re-prompt the user for consent before obtaining another refresh token. If you need to re-prompt the user for consent, include the prompt parameter in the authorization code request, and set the value to consent. After your application receives the refresh token, it can obtain new access tokens at any time. See the section on refresh tokens for more information. The next time your application requests an authorization code for that user, the user will not be asked to grant consent (assuming they previously granted access, and you are asking for the same scopes). As expected, the response includes an authorization code which may be redeemed. However, unlike the first time an authorization code is exchanged for a given user, a refresh token will not be returned from the authorization code exchange. The following is an example of such a response { "access_token" "1/fFAGRNJru1FQd77BzhT3Zg", "expires_in" 3920, "token_type" "Bearer", } Using a refresh token As indicated in the previous section, a refresh token is obtained in offline scenarios during the first authorization code exchange. In these cases, your application may obtain a new access token by sending a refresh token to the Google OAuth 2.0 Authorization server. To obtain a new access token this way, your application sends an HTTPS POST request to https //www.googleapis.com/oauth2/v4/token. The request must include the following parameters FieldDescription refresh_tokenThe refresh token returned from the authorization code exchange. client_idThe client ID obtained from the API Console. client_secretThe client secret obtained from the API Console. grant_typeAs defined in the OAuth 2.0 specification, this field must contain a value of refresh_token. Such a request will look similar to the following POST /oauth2/v4/token HTTP/1.1 Host www.googleapis.com Content-Type application/x-www-form-urlencoded client_id=8819981768.apps.googleusercontent.com client_secret={client_secret} refresh_token=1/6BMfW9j53gdGImsiyUH5kU5RsR4zwI9lUVX-tqf8JXQ grant_type=refresh_token As long as the user has not revoked the access granted to your application, the response includes a new access token. A response from such a request is shown below { "access_token" "1/fFBGRNJru1FQd44AzqT3Zg", "expires_in" 3920, "token_type" "Bearer", } Note that there are limits on the number of refresh tokens that will be issued; one limit per client/user combination, and another per user across all clients. You should save refresh tokens in long-term storage and continue to use them as long as they remain valid. If your application requests too many refresh tokens, it may run into these limits, in which case older refresh tokens will stop working. Revoking a token In some cases a user may wish to revoke access given to an application. A user can revoke access by visiting Account Settings. It is also possible for an application to programmatically revoke the access given to it. Programmatic revocation is important in instances where a user unsubscribes or removes an application. In other words, part of the removal process can include an API request to ensure the permissions granted to the application are removed. PHPPYTHONRUBYHTTP/REST To programmatically revoke a token, your application makes a request to https //accounts.google.com/o/oauth2/revoke and includes the token as a parameter curl https //accounts.google.com/o/oauth2/revoke?token={token} The token can be an access token or a refresh token. If the token is an access token and it has a corresponding refresh token, the refresh token will also be revoked. If the revocation is successfully processed, then the status code of the response is 200. For error conditions, a status code 400 is returned along with an error code. Note Following a successful revocation response, it might take some time before the revocation has full effect. Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Using OAuth 2.0 with the Google API Client Library for Java {{ Authorization Code Flow https //code.google.com/p/google-api-java-client/wiki/OAuth2#Authorization_Code_Flow 実装にはGoogleAuthorizationCodeFlowを用いる。 まず、API使用が登録済みであること。client id, client secret等々をもらっておく Authorization codeをもらう持っていなければ、認証URLへ。 ユーザIDをもとに、AuthorizationCodeFlow.loadCredential(String userID)を呼び出す既に証明書を持っているかを確認。持っていれば、終了。 認証されると、"code"と一緒にリダイレクトされる。 "code"を使って access token を要求する AuthorizationCodeFlow.newTokenRequest(String)でアクセストークン(access token)を要求。AuthorizationCodeFlow.createAndStoreCredential(TokenResponse, String) http //javadoc.google-oauth-java-client.googlecode.com/hg/1.18.0-rc/com/google/api/client/auth/oauth2/AuthorizationCodeFlow.html#createAndStoreCredential(com.google.api.client.auth.oauth2.TokenResponse,%20java.lang.String)]] で、証明書を取得し保管。 レスポンスからaccess tokenを取得 ※Lower-Levelの実装方法もある https //code.google.com/p/google-api-java-client/wiki/OAuth2#Authorization_Code_Flow }} トークンのリクエスト リクエスト先 https //accounts.google.com/o/oauth2/authSSLを使用すること。httpはダメ リクエストに加えるのは Parameter Values 必須 Description response_type "code" ◯ Webサーバアプリケーションでは code で決め打ち client_id client_id ◯ API使用の登録で貰ったID.忘れていたらconsoleで確認 redirect_uri One of the redirect_uri ◯? リダイレクト先は複数登録されているので、どこにリダイレクトするのかここで書いておく。 scope Space-delimited set of permissions that the application requests. ◯ APIでどこまでユーザーのデータにアクセスするか(できるか)。複数ある場合はスペース区切り。どのような値を入れるかは、各APIのリファレンスページ(the APIs Explorer)参照。極力「最小」にしておく。必要なら後で追加認証をする感じで。 state Any string レスポンスを受け取る際に使える「状態」。cross-site request forgery (CSRF)の対策?なので、強く推奨。レスポンスを受け取って、これを確認すれば、変なとこで使われていないか、確認できる。 access_type offline or online ユーザがブラウザを使ってない時でもアプリケーションがアクセスするかどうか。自動的にトークンのリフレッシュが必要ならoffline。 approval_prompt force or auto optional デフォルトでauto 接続の度にプロンプトを出して訊くかどうか? login_hint email address or sub identifier optional どのユーザが認証を行おうとしているかアプリケーション側でわかっている場合、(例えばそのユーザのemailアドレスを)パラメータとして渡すことができる。 include_granted_scopes true or false optional If this is provided with the value true, and the authorization request is granted, the authorization will include any previous authorizations granted to this user/application combination for other scopes; see Incremental Authorization. リクエストのスペース等々はエスケープする。 java.net.URLEncoder とか サンプル(改行は見やすくするため) https //accounts.google.com/o/oauth2/auth? scope=email%20profile state=security_token%3D138r5719ru3e1%26url%3Dhttps //oa2cb.example.com/myHome redirect_uri=https%3A%2F%2Foauth2-login-demo.appspot.com%2Fcode , response_type=code client_id=812741506391.apps.googleusercontent.com approval_prompt=force リクエストが正しく通れば、以下が返ってくる access tokens refresh tokens authorization codes. java? AuthorizationCodeFlow.newAuthorizationUrl()が使える? リダイレクトのURLから、codeを処理する Handling the response The response will be sent to the redirect_uri as specified in the request URL. If the user approves the access request, then the response contains an authorization code and the state parameter (if included in the request). If the user does not approve the request, the response contains an error message. All responses are returned to the web server on the query string, as shown below 認証失敗 https //oauth2-login-demo.appspot.com/code? bold(){error=access_denied} state=security_token%3D138r5719ru3e1%26url%3Dhttps //oa2cb.example.com/myHome 認証成功 https //oauth2-login-demo.appspot.com/code?state=security_token%3D138r5719ru3e1%26url%3Dhttps //oa2cb.example.com/myHome bold(){code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7} リダイレクト先が通常のHTMLページの場合は、そのままURLが見える、つまりcodeが見えてしまう。 Scripts can read the URL directly, and all resources may be sent the URL in the Referer HTTP header. Carefully consider if you want to send authorization credentials to all resources on that page (especially third-party scripts such as social plugins and analytics). この問題を避けるために、サーバでリクエストを扱って、それからパラメータを含まない形で別のURLにリダイレクトするべき。 authorization code と access token の交換 After the web server receives the authorization code, it may exchange the authorization code for an access token and a refresh token. This request is an HTTPS POST to the URL https //www.googleapis.com/oauth2/v3/token, and includes the following parameters Field Description code authorization code client_id The client ID client_secret The client secret obtained from the Developers Console redirect_uri One of the redirect URIs grant_type ここでは "authorization_code" の決め打ち レスポンス例(成功時) { "access_token" "ya29.vAHSwBFxEzkYKAeqk461biUJ9dqSD8KglnarHgBaR7q7Ih_4TlT71KEh07QBR6_tfLVv", "token_type" "Bearer", "expires_in" 3600}
https://w.atwiki.jp/appengine/pages/16.html
原文 id hamatsu1974 さんの 翻訳エントリ ※このページは翻訳の途中です。 Google App Engineってなに? Google App EngineはGoogleのインフラストラクチャを使用して、あなたのWebアプリケーションを走らせることができます。 App Engineアプリケーションはビルド、メンテナンス、データやトラフィックの増大に対するスケーリングが超簡単にできてしまいます。 App Engineを使えば、メンテナンスするべきサーバーはもうどこにもありません。 あなたのアプリケーションをアップロードして、ユーザーにサービスを提供するだけです。 あなたはappspot.com上にアプリケーションが使うドメイン名を自由につけて使用するか、 Google Apps に独自のドメインを割り当てることができます。 あなたはアプリケーションを全世界に公開するか、あなたの活動のメンバーにアクセスを制限することができます。 App Engineをはじめるのにお金はかかりません。 フリーのアカウントにサインアップしさえすれば、何のチャージも義務もなく、アプリケーションを開発して世界にパブリッシュできます。 フリーのアカウントでは500MBのストレージ、十分なCPU、月に500万ページビューまで使用することが出来ます。 Google App Engineがプレビューリリースの間はフリーのアカウントだけが利用可能です。 近いうちに追加のリソースを購入することが出来るようになるでしょう。 アプリケーション開発環境 Google App Engineは、大量のデータやトラフィックを扱うことになるような場合でも、安定して稼動するアプリケーションを簡単に構築することが出来ます。 開発環境には以下の機能があります。 ダイナミックなWebを提供し、一般的なWebテクノロジーをフルサポート クエリ、ソート、トランザクションによる永続的なストレージ 自動的なスケーリングとロードバランシング Googleアカウントを使ったユーザー認証とメール送信のAPI群 Google App EngineをローカルPC上でシミュレートするフル機能のローカル開発環境 Google App Engineアプリケーションは Python言語 を使うように実装されています。 ランタイム環境はPython言語をフルサポートし、Pythonのほとんどの標準ライブラリを含んでいます。 現在、PythonはGoogle App Engineでサポートされている唯一の言語ですが、 将来たくさんの言語をサポートすることを楽しみにしています。 サンドボックス アプリケーションはOSへの限られたアクセスを提供されたセキュアな環境で実行されます。 これらの制限があることでApp Engineに、いろいろなサーバーをまたがったアプリケーションへのWebリクエストを処理することを可能にし、トラフィックに合わせて、サーバーを起動させたり停止させたりすることが出来るようになります。 サンドボックスはあなたのアプリケーションを、ハードウェア、OS、Webサーバーの物理的な場所からも独立した、信頼できるセキュアな環境に分離させます。 例えば、セキュアなサンドボックス環境で制限されていることは アプリケーションはインターネット上にある他のコンピュータにアクセスするには、提供されたURLのフェッチ、Eメール、API群を使用するしかありません。他のコンピュータからアプリケーションにアクセスするにはHTTPかHTTPSを標準ポートでアクセスすることしか出来ません。 アプリケーションはファイルシステムに書き込みが出来ません。アプリケーションはアプリケーションのコードによってアップロードされたファイルしか読むことしか出来ません。アプリケーションはリクエストの間保持するすべてのデータにApp Engine datastoreを使用しなければいけません。 アプリケーションコードはWebリクエストのレスポンスとしてのみ動作し、数秒以内にレスポンスを返さなければいけません。リクエストハンドラからサブプロセスを生成したり、レスポンスを返した後にコードを実行することは出来ません。 Pythonランタイム環境 App EngineはPython言語を使ったランタイム環境を提供します。 他のプログラミング言語とランタイム環境設定は将来的にリリースされるでしょう。 Pythonランタイム環境はPythonのヴァージョン 2.5.2を使用しています。 環境には Pythonの標準ライブラリ を含んでいます。もちろんサンドボックスを壊すようなライブラリメソッドは制限されています。 ソケットをオープンしたりファイルに書き込んだりするようなことをしても失敗します。 利便性のために標準ライブラリのうちのいくつかのモジュールのコアな機能はランタイム環境でサポートされておらず、それらをインポートしようとした時にエラーになるでしょう。 アプリケーションコードは全てPythonで書かれていなければいけません。 C言語による拡張はサポートされていません。 Python環境は datastore 、 Googleアカウント 、 URLフェッチ や Eメール サービスのリッチなPython APIを提供します。 App Engineはまた、webappと呼ばれる簡単にアプリケーションの構築を開始するためのシンプルなPython Webアプリケーションフレームワークを提供します。 利便性のためにApp Engineには DjangoというWebアプリケーションフレームワーク のヴァージョン0.96.1を含んでいます。 気をつけるのはApp EngineのdatastoreはDjangoのいくつかのコンポーネントが必要とするリレーショナルデータベースではないということです。 いくつかのコンポーネントのひとつのDjangoテンプレートエンジンを使うには他にもう少し努力が必要です。 App EngineでDjangoを使う際のTipsの 記事 を見てください。 あなたはPure Pythonで書かれていてサポートされていないライブラリを必要としないサードパーティのライブラリをあなたのアプリケーションと一緒にアップロードすることが出来ます。 これ以上のPythonランタイムに関する情報はPythonランタイム環境?を見てください。 データストア App Engineはクエリエンジンとトランザクション機能を持つ、パワフルな分散データベースストレージを提供します。 分散Webサーバーがトラフィックに合わせて成長するように、分散データベースもデータ量によって成長します。 App Engineのデータストアは従来のリレーショナルデータベースとは違います。データオブジェクト(または「エンティティ」)には、種類とプロパティのセットがあります。クエリを使って、指定した種類のエンティティをプロパティの値によってフィルターにかけ、ソートした状態で取得することができます。 プロパティの値は サポートされた値 ならばどれでも指定することが出来ます。 The Python API for the datastore includes a data modeling interface that can define a structure for datastore entities. A data model can indicate that a property must have a value within a given range, or provide a default value if none is given. Your application can provide as much or as little structure to the data as it needs. The datastore uses optimistic locking for concurrency control. An update of a entity occurs in a transaction that is retried a fixed number of times if other processes are trying to update the same entity simultaneously. Your application can execute multiple datastore operations in a single transaction which either all succeed or all fail, ensuring the integrity of your data. The datastore implements transactions across its distributed network using "entity groups." A transaction manipulates entities within a single group. Entities of the same group are stored together for efficient execution of transactions. Your application can assign entities to groups when the entities are created. For more information about the datastore, see the Datastore API reference.
https://w.atwiki.jp/against_streetview/pages/21.html
ストリートビューに限らず、Google社とプライバシーに関する問題を知る上で参考になる記事を紹介します。 プライバシー保護団体とGoogleが中傷合戦へ!? (@IT) Googleは消費者を広く監視しており、プライバシーに対して敵対的――、6月9日に消費者のプライバシー保護を目的に活動するNPO団体、プライバシーインターナショナルが公表した調査結果(A Race to the Bottom - Privacy Ranking of Internet Service Companies)が波紋を広げている。 調査対象となった23の企業またはサービスのうち、最も悪い評価である「プライバシーに敵対的」のラベルを付けられたのはGoogleのみ。 Google幹部の自宅をプライバシー保護団体がさらしものに (ITmedia News) プライバシー保護団体がGoogle Earthを使ってGoogle取締役の自宅を突き止めてみせた。Googleのプライバシーをめぐる姿勢は偽善的だと批判している。 非営利組織のNLPC(National Legal and Policy Center)は、カメラと衛星画像で地球上のロケーション分布を示すGoogleのアプリケーションStreet ViewとGoogle Earthを使い、カリフォルニア州パロアルトにあるGoogle取締役の自宅をピンポイントで突き止めてみせた。 高木浩光@自宅の日記 通信プラットフォーム研究会 傍聴録 (Google社の発言あり) グーグル社の人のプライバシーに対する見解。 グーグル(藤田一夫オブザーバー) 最後にプライバシーについて。確かに問題があるかもしれないが、日本のプライバシーに対する感覚は、アメリカ、イギリスとでは違うのではないか。日本では、マンションとかはまた違うかもしれないが、一戸建てでは名前を表札に書いている。名前まで。わざわざ自分の名前を公道に出しているわけだから、プライバシーなんて気にしていない。(会場苦笑。)それが、ネットの世界でだけ気にするというのはうーんどうかなと思う。(会場冷笑。) Google Mapsの「Street View」めぐり、プライバシー侵害訴訟 (CNET Japan) ペンシルベニア州ピッツバーグの夫婦が、Google MapsのStreet Viewにプライバシーを侵害されたとして、Googleを訴えた。 Google Desktop 3にプライバシー侵害の恐れ、EFFが利用停止呼びかけ (Enterprise Watch) 米国の非営利団体、電子フロンティア財団(EFF)は2月9日(米国時間)、米Googleが同日公開した最新のデスクトップツール「Google Desktop 3」(ベータ版)に、利用者のプライバシーを侵す危険があるとして消費者に利用停止を呼びかけた。新機能の「Search Across Computers」から個人情報が流出する危険性を指摘している。 Gmailはプライバシー侵害の危険な前例となりうる~世界の市民団体が懸念 (INTERNET Watch) Googleが4月1日に発表したメールサービス「Gmail」が、世界中のプライバシー団体からの非難を浴びている。4月6日に28団体がGoogle に対して公開書簡を送付したが、19日には賛同者が31団体にまで増え、今やGmailのプライバシーポリシーに関する議論が世界中で行なわれている状況だ。 『Google』の検索履歴サービス、プライバシーに懸念も (WIRED VISION) 米グーグル社(カリフォルニア州マウンテンビュー)は、検索エンジン『Google』(グーグル)に、ユーザーの過去の検索キーワードと検索結果をすべて見られるようにする新機能をベータ版として追加した。この機能は役に立つだろうが、同時にコンピューターに覗き穴を作って、ユーザーにきまりの悪い思いをさせることになるかもしれない。 『ワールド・プライバシー・フォーラム』の代表で、プライバシー権に詳しいパム・ディクソン氏は、この新サービスのせいで、詮索好きな人間や、さらには政府さえもが、ユーザーの検索履歴のすべてを容易に把握できるようになってしまうことを不安視する。
https://w.atwiki.jp/maguroi/pages/13.html
Google Maps画像リンク元01